// pages/community/community.js
import CommunityModule from '../../models/3.0/community'
import {category} from '../../models/explore'
import { Login } from '../../models/login'
const newCategory =new category()
Page({
  data: {
    active: 0,
    activeKey: 0,
    list: [],
    joinList: [],
    checkedIndex: 0,
    attentionState:0,
    type:''
  },
  getCategory(){
    newCategory.getCategory(res=>{
    this.setData({
      joinList:res,
    })
    })
  },

  // 选择圈子时候修改上一页的值?
  choice(event){
    let index = event.currentTarget.dataset.index
    console.log(index,'index');
    let pages = getCurrentPages()
    let prevPage = pages[pages.length - 2]
    prevPage.setData({
      'community.id': index.id,
      'community.name':index.name
    })
    wx.navigateBack()
  },

  switch(e) {
    const index = e.currentTarget.dataset.index
    this.setData({
      checkedIndex: index
    })
    if (index == 1) {
      // this.getMyJoinCommunityList()
    }
  },

  getCommunityList() {
    CommunityModule.list().then((res) => {
      this.setData({
        list: res,
    })
  })
  },

  follow(e) {
    const item = e.currentTarget.dataset.item
    CommunityModule.follow({
      momentGroupId: item.id,
      type: 1,
      userId:wx.getStorageSync('userInfo').user_id || 0,
    }).then(res => {
      this.getCommunityList()
    })
  },
  join() {},
  check(e){
    const item = e.currentTarget.dataset.item
    CommunityModule.noFollow({
      groupId:item.id,  
    }).then(res => {
      this.getCommunityList()
    })
  },
  onLoad:function(options) {
  this.setData({
    type: options.type
  })
  },
  onShow() {
    this.getCommunityList()
    this.getCategory()

  }
})
